package demo4;

import java.util.Objects;

public class Person {
    public String name ;

    public Person(String name) {
        this.name = name;
    }


    /*public boolean equals(Object obj) {
        //手动重写
        Person tmp = (Person)obj;//转回Person类
        return (tmp.name).equals(this.name);//调用String的equals
    }*/

    @Override
    public boolean equals(Object o) {
        //自动生成
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Person person = (Person) o;
        return Objects.equals(name, person.name);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name);
    }

    @Override
    public String toString() {
        return "name: "+name;
    }
}
